//
// Created by 10334 on 2022/9/26.
//

#include "initialize_demo.h"
#include "element.h"

vector<Node *> *demo::initialize_all_node(string *net_case) {
	auto all_node = new vector<Node *>;
	if (*net_case == "demo") {
		{
			/*{
			"identifier": 0,
			"category": "module"
			}*/
			auto new_node = new Node(0, new string("module"), 0, 0, nullptr);
			all_node->push_back(new_node);
		}
		{
			/*{
			"identifier": 1,
			"category": "switch"
			}*/
			auto new_node = new Node(1, new string("switch"), 0, 0, nullptr);
			all_node->push_back(new_node);
		}
		{
			/*{
			"identifier": 2,
			"category": "module"
			}]*/
			auto new_node = new Node(2, new string("module"), 0, 0, nullptr);
			all_node->push_back(new_node);
		}
		return all_node;
	} else {
		return nullptr;
	}
}

vector<Link *> *demo::initialize_all_link(string *net_case) {
	auto all_link = new vector<Link *>;
	if (*net_case == "demo") {
		{
			/*{
				"identifier": 0,
				"src_node": 0,
				"des_node": 1
			}*/
			auto new_link = new Link(0, 0, 1, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		{
			/*{
				"identifier": 1,
				"src_node": 1,
				"des_node": 2
			}*/
			auto new_link = new Link(1, 1, 2, 0, 0, nullptr);
			all_link->push_back(new_link);
		}
		return all_link;
	} else {
		return nullptr;
	}
}

vector<Function *> *demo::initial_all_function(string *net_case) {
	auto all_function = new vector<Function *>;
	if (*net_case == "demo") {
		{
			/*{
				"identifier": 0,
				"contain_task": [0,1]
			}*/
			auto new_function = new Function(0, new vector<int>({0, 1}), 0, 0);
			all_function->push_back(new_function);
		}
		return all_function;
	} else {
		return nullptr;
	}
}

vector<Task *> *demo::initialize_all_task(string *net_case, vector<Node *> *all_node) {
	auto all_task = new vector<Task *>;
	if (*net_case == "demo") {
		{
			/*{
				"identifier": 0,
				"res_node": 0,
				"period": 20,
				"length": 0
			}*/
			if (*(*all_node)[0]->category == "module") {
				//角标是res_node的值
				auto new_task = new Task(0, (*all_node)[0], 20, 0, new string("undone"), -1, -1, -1);
				all_task->push_back(new_task);
			} else {
				fprintf(stderr, "Wrong! task %d is allocated to switch", 0);
			}
		}
		{
			/*{
				"identifier": 1,
				"res_node": 2,
				"period": 20,
				"length": 0
			}*/
			if (*(*all_node)[2]->category == "module") {
				//角标是res_node的值
				auto new_task = new Task(1, (*all_node)[2], 20, (0 * 10 + 2000) / 3.0, new string("undone"), -1, -1,
				                         -1);
				all_task->push_back(new_task);
			} else {
				fprintf(stderr, "Wrong! task %d is allocated to switch", 1);
			}
		}
		return all_task;
	} else {
		return nullptr;
	}
}

vector<Message *> *demo::initialize_all_message(string *net_case, vector<Task *> *all_task) {
	auto all_message = new vector<Message *>;
	if (*net_case == "demo_large") {
		{
			/*{
				"identifier": 0,
				"src_task": 0,
				"des_task": 1,
				"length": 5
			}*/
			auto new_message = new Message(0, 0 + 12, 1 + 12, 10, 5,
			                               0, new string("undone"), -1,
			                               nullptr, nullptr, -1);
			all_message->push_back(new_message);
		}
		return all_message;
	} else {
		return nullptr;
	}
}